<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Chapter 8. Behaviours</title>
    <link rel="stylesheet" href="style.css" type="text/css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
    <link rel="start" href="index.html" title="Clutter编程" />
    <link rel="up" href="index.html" title="Clutter编程" />
    <link rel="prev" href="effects-example.html" title="示例" />
    <link rel="next" href="behaviour-example.html" title="示例" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">Chapter 8. Behaviours</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="effects-example.html"><img src="../icons/prev.png" alt="Prev" /></a> </td>
          <th width="60%" align="center"> </th>
          <td width="20%" align="right"> <a accesskey="n" href="behaviour-example.html"><img src="../icons/next.png" alt="Next" /></a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="chapter" lang="en" xml:lang="en">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title"><a id="sec-behaviours"></a>Chapter 8. Behaviours</h2>
          </div>
        </div>
      </div>
      <div class="toc">
        <p>
          <b>Table of Contents</b>
        </p>
        <ul>
          <li>
            <span class="sect1">
              <a href="sec-behaviours.html#id2975058">使用 Behaviours</a>
            </span>
          </li>
          <li>
            <span class="sect1">
              <a href="behaviour-example.html">示例</a>
            </span>
          </li>
        </ul>
      </div>
      <div class="sect1" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h2 class="title" style="clear: both"><a id="id2975058"></a>使用 Behaviours</h2>
            </div>
          </div>
        </div>
        <p><a class="link" href="sec-effects.html" title="Chapter 7. Effects">Effects</a> API 简单易用，但很多场合需要直接用 behaviours 实现更复杂的操作。
</p>
        <p>
尽管可以利用 <code class="classname">ClutterTimeline</code> 的 <code class="literal">new-frame</code> 信号为每一帧设置 actor 的属性，但 <span class="application">Clutter</span> 也提供了 <code class="literal">Behaviours</code> ，它可以使用简单的数学计算随时间改变某个 actor 的某个属性。然而，不像 <a class="link" href="sec-effects.html" title="Chapter 7. Effects">effect</a> API，直接使用 behaviours 可以同时控制多个 actor ，并且随时间改变 behaviour 的参数。
</p>
        <p>
例如，<code class="classname">ClutterBehaviourPath</code> 沿着指定路径移动 actor，通过调用一个 <code class="literal">alpha</code> 回调，计算每帧在路径上的位置。alpha 回调和时间线<code class="classname">ClutterTimeline</code> 构成了 <code class="classname">ClutterAlpha</code> 对象。 
</p>
        <div class="figure">
          <a id="figure-path-alpha-func"></a>
          <p class="title">
            <b>Figure 8.1. Effects of alpha functions on a path.</b>
          </p>
          <div class="figure-contents">
            <div class="screenshot">
              <div>
                <img src="./figures/path-alpha-func.png" alt="Effects of alpha functions on a path." />
              </div>
            </div>
          </div>
        </div>
        <br class="figure-break" />
        <p>你的<code class="literal">alpha</code> 回调需要调用<code class="function">clutter_alpha_get_timeline()</code>、<code class="function">clutter_timeline_get_current_frame</code> 和 <code class="function">clutter_timeline_get_n_frames()</code>，返回一个基于时间线当前帧和总帧数的值。<span class="application">Clutter</span> 提供了几个内建的回调，如<code class="function">CLUTTER_ALPHA_SINE</code>，用这些内建的回调创建动画变得非常容易。 
</p>
        <p>
如果 behaviour  的时间线开始了，那么 behaviour 的终点将结束时间线，时间线被设置成循环状态除外。。例如，一个 actor 将沿着一条路径移动，直到它到达终点，花费的时间是总帧数/每秒帧数。
</p>
        <p>
与 actors 类似，<code class="classname">ClutterAlpha</code> 是 "floating references" 所以不需要 unref 它，但 behaviour 不是 floating reference，所以用完后需要 unref 。你可以在 unref 时间线的同时 unref behaviour，比如在时间线的 <code class="literal">completed</code> 信号处理函数中进行。</p>
        <p>
          <a class="ulink" href="http://clutter-project.org/docs/clutter/0.8/ClutterBehaviour.html" target="_top">ClutterBehaviour Reference</a>
        </p>
        <p>
          <a class="ulink" href="http://clutter-project.org/docs/clutter/0.8/ClutterAlpha.html" target="_top">ClutterAlpha Reference</a>
        </p>
        <p><span class="application">Clutter</span> 提供了如下标准 behaviour：
</p>
        <div class="itemizedlist">
          <ul type="disc">
            <li>
              <p><a class="ulink" href="http://clutter-project.org/docs/clutter/0.8/ClutterBehaviourBspline.html" target="_top">ClutterBehaviourBspline</a>: 沿 bezier 曲线移动；</p>
            </li>
            <li>
              <p><a class="ulink" href="http://clutter-project.org/docs/clutter/0.8/ClutterBehaviourDepth.html" target="_top">ClutterBehaviourDepth</a>: 沿 Z 轴移动；</p>
            </li>
            <li>
              <p><a class="ulink" href="http://clutter-project.org/docs/clutter/0.8/ClutterBehaviourEllipse.html" target="_top">ClutterBehaviourEllipse</a>: 沿椭圆形曲线移动；</p>
            </li>
            <li>
              <p><a class="ulink" href="http://clutter-project.org/docs/clutter/0.8/ClutterBehaviourOpacity.html" target="_top">ClutterBehaviourOpacity</a>: 改变 actor 的透明度；</p>
            </li>
            <li>
              <p><a class="ulink" href="http://clutter-project.org/docs/clutter/0.8/ClutterBehaviourPath.html" target="_top">ClutterBehaviourPath</a>: actor 沿指定路径移动；</p>
            </li>
            <li>
              <p><a class="ulink" href="http://clutter-project.org/docs/clutter/0.8/ClutterBehaviourRotate.html" target="_top">ClutterBehaviourRotate</a>: 旋转；</p>
            </li>
            <li>
              <p><a class="ulink" href="http://clutter-project.org/docs/clutter/0.8/ClutterBehaviourScale.html" target="_top">ClutterBehaviourScale</a>: 缩放 actor。</p>
            </li>
          </ul>
        </div>
        <p>
</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="effects-example.html"><img src="../icons/prev.png" alt="Prev" /></a> </td>
          <td width="20%" align="center"> </td>
          <td width="40%" align="right"> <a accesskey="n" href="behaviour-example.html"><img src="../icons/next.png" alt="Next" /></a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">示例 </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">
              <img src="../icons/home.png" alt="Home" />
            </a>
          </td>
          <td width="40%" align="right" valign="top"> 示例</td>
        </tr>
      </table>
    </div>
  </body>
</html>
